package com.ohs.ohsoa.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.OvertimeLeaveInfoParamDto;
import com.ohs.ohsoa.system.service.OvertimeLeaveInfoService;
import com.ohs.ohsoa.system.vo.OvertimeLeaveInfoParamVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.PageHelper;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "加班欠勤管理", tags = "加班欠勤管理")
@RestController
@RequestMapping("/overtimeleaveinfo")
public class OvertimeleaveinfoController {

    @Resource
    private OvertimeLeaveInfoService overtimeleaveinfoService;

    /**
     * 获取列表信息
     *
     * @param pageParam 檢索用參數
     * @return 列表信息
     */
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取列表信息")
    public ResultBean<PageInfo<OvertimeLeaveInfoParamVo>> overtimeleaveinfoSelectList(
            @RequestBody PageParam<OvertimeLeaveInfoParamDto> pageParam) {
        List<OvertimeLeaveInfoParamVo> res = overtimeleaveinfoService.overtimeleaveinfoSelectList(pageParam);
        return ResultBean.success(PageHelper.startPage(pageParam, res));
    }

    /**
     * 获取详细信息
     *
     * @param overtimeLeaveInfoParamDto 详细信息数据
     * @return 详细信息
     */
    @UserLoginToken
    @PostMapping(value = "/select")
    @ApiOperation(httpMethod = "POST", value = "根据id查询详细信息")
    public ResultBean<?> overtimeleaveinfoSelect(@RequestBody OvertimeLeaveInfoParamDto overtimeLeaveInfoParamDto) {
        return ResultBean.success(overtimeleaveinfoService.overtimeleaveinfoSelect(overtimeLeaveInfoParamDto));
    }

    /**
     * 新增加班欠勤信息
     *
     * @param overtimeLeaveInfoParamDto 信息数据
     * @return 新增结果
     */
    @UserLoginToken
    @PostMapping(value = "/insert")
    @ApiOperation(httpMethod = "POST", value = "新增加班欠勤信息")
    public ResultBean<Boolean> overtimeleaveinfoInsert(@RequestBody @Valid OvertimeLeaveInfoParamDto overtimeLeaveInfoParamDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(overtimeleaveinfoService.overtimeleaveinfoInsert(overtimeLeaveInfoParamDto));
    }

    /**
     * 删除加班欠勤信息
     *
     * @param overtimeLeaveInfoParamDto 欠勤信息数据
     * @return 删除结果
     */
    @UserLoginToken
    @DeleteMapping(value = "/delete")
    @ApiOperation(httpMethod = "DELETE", value = "加班欠勤信息删除")
    public ResultBean<Boolean> overtimeleaveinfoDelete(@RequestBody OvertimeLeaveInfoParamDto overtimeLeaveInfoParamDto) {
        return ResultBean.success(overtimeleaveinfoService.overtimeleaveinfoDelete(overtimeLeaveInfoParamDto));
    }

    /**
     * 修改加班欠勤信息
     *
     * @param overtimeLeaveInfoParamDto 欠勤信息数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改加班欠勤信息")
    public ResultBean<Boolean> overtimeleaveinfoUpdate(@RequestBody @Valid OvertimeLeaveInfoParamDto overtimeLeaveInfoParamDto,BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(overtimeleaveinfoService.overtimeleaveinfoUpdate(overtimeLeaveInfoParamDto));
    }

    /**
     * 审核通过
     *
     * @param overtimeLeaveInfoParamDto 信息数据
     * @return 更新信息
     */
    @UserLoginToken
    @PutMapping(value = "/verified")
    @ApiOperation(httpMethod = "PUT", value = "审核通过")
    public ResultBean<Boolean> overtimeleaveinfoVerified(@RequestBody OvertimeLeaveInfoParamDto overtimeLeaveInfoParamDto) {
        return ResultBean.success(overtimeleaveinfoService.overtimeleaveinfoVerified(overtimeLeaveInfoParamDto));
    }

}
